package com.jsits.v2x.common.connection.socket;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolDecoderOutput;

public class MessageDecoder extends CumulativeProtocolDecoder
{
	/*
	 * Socket连接类
	 */
	private SocketBase socketBase;
	
	public void setSocketBase(SocketBase socketBase) 
	{
		this.socketBase = socketBase;
	}
	
	/*
	 * 客户端接收的所有消息解析入口函数
	 * @see org.apache.mina.filter.codec.CumulativeProtocolDecoder#doDecode(org.apache.mina.core.session.IoSession, org.apache.mina.core.buffer.IoBuffer, org.apache.mina.filter.codec.ProtocolDecoderOutput)
	 */
	public boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception 
	{
		boolean result = socketBase.handleBuffer(in, out, session);
		if (result) {
			in.free();
		}
		return result;
	}
	
    public void dispose(IoSession session) throws Exception 
    {
    	
    }
}
